package com.lwl.Algorithmic_data_structure.class13贪心算法;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author lwl
 * @Description 给一个字符串数组，求出将该数组字符串拼接起来的字典序最小的值
 * @date 2023/6/1 10:40
 */
public class Code02getMinDictionary {

    public String getMinDictionary(String[] strs) {
        if (strs == null || strs.length == 0) {
            return null;
        }
        Arrays.sort(strs, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1 + o2).compareTo(o2 + o1);
            }
        });
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
            res.append(strs[i]);
        }
        return res.toString();
    }

}
